home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Developer Toolbox 6.1
/
SGI Developer Toolbox 6.1 - Disc 1.iso
/
toolbox
/
src
/
exampleCode
/
opengl
/
cap
/
README
< prev
next >
Wrap
Text File
|
1996-11-11
|
4KB
|
81 lines
~4Dgifts/toolbox/src/exampleCode/opengl/cap README
Open GL Interference Checking
=============================
Capping is a trick employed so that we can use hollow models
to portray solids, and is used in applications where objects
could be clipped (such as CAD). Interference checking is
a method of showing the regions of intersection between two
separate objects.
The program allows the user to toggle capping on and off. Note
that there is a performance hit you take with capping on. The
reasons for this are outlined below when I discuss the algorithm.
This open gl example is based on Kurt Akeley's 'cap' program.
It is by no means as robust in a demonstrational sense, meaning
it does not read object in from a file, nor can one move around the
clipping planes or the viewpoint.
What it does do is to apply a clipping plane in the XY plane at z=0,
and bring up two torii. The clipped torii are capped using the same
material as the rest of each respective surface. The interference
between the two objects is shown in red. The yellow square is an
outline of a plane coinciding to the arbitrary clipping plane 0.
The axes are drawn at the origin to indicate the orientation of the
clipping plane.
The capping and interference checking are both done using the
stencil buffer.
The capping is done by rendering each object in the scene twice.
The first time, the objects are each drawn with backfacing on
(since the capping will prevent the user from seeing the inner
portions of the clipped objects). Then we disable writes to the
color and depth buffers. We'll use the low order bit of the stencil
buffer to determine where we've drawn part of the object. Then
we'll draw the object again, using the stencil buffer to keep
track of which pixels we've tried to draw something to. Where the
value in the stencil buffer is odd, the inside of the solid was
(rather would have been) visible.
After the object is rendered for the second time, we draw the clipping
plane, using the same material property as the object's. In order
to make sure that the cap is drawn correctly, we do two things. First,
we shut off the clipping plane (otherwise the cap itself could be
clipped). Then, we transform the origin to the location of the clipping
plane. This prevents any problems related to viewer position from
occuring. For example, if the origin of the model view matrix were
not where we expected, the cap might be drawn at an offset to its
expected position.
The interference checking is done after all of the objects in the scene
are drawn with their caps. Since the values in the stencil buffer
are still intact, we draw a large rectangle stenciling those regions
with pixel access counts of two or greater. In this example, we
draw a red rectangle, ergo the name "little red cap".
Objects can be animated to ensure the capping and interference
checking is done in real time.
To change the objects, their properties, or transforms, edit the
shapes data structure in ogl_interfere.c. This data structure will
also take a uniform scaling factor if you wish to grow or shrink
each shape.
At this writing there is a known bug in hardware-supported stencil
buffers that cause the all shapes (except the first) to be capped
in their entirety, not just in the clipped areas. I have observed
this on Extreme, Elan, and Reality Engine graphics and there is
a bug filed against it. Hopefully by the time anyone reads this,
it will have been fixed. You can see the working version on
machines with XL (newport) or starter graphics (since stencilling is
software-supported).
Paul C. David
pcd@sgi.com
1/94